﻿// --------------------------------
// <copyright file="TableColumnCollectionTest.cs" company="TRONSoft">
//     Copyright (c) TRONSoft.
// </copyright>
// <license>
//   This source code is subject to terms and conditions of the Microsoft
//   Public License. A copy of the license can be found in the License.html
//   file at the root of this distribution. If you cannot locate the
//   Microsoft Public License, please send an email to dlr@microsoft.com.
//   By using this source code in any fashion, you are agreeing to be bound 
//   by the terms of the Microsoft Public License. You must not remove this
//   notice, or any other, from this software.
// </license>
// <author>Tron</author>
// ---------------------------------

using System;
using System.Data;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace Tronsoft.Actucal.Tables.Test
{
    
    
    /// <summary>
    ///This is a test class for TableColumnCollectionTest and is intended
    ///to contain all TableColumnCollectionTest Unit Tests
    ///</summary>
    [TestClass()]
    public class TableColumnCollectionTest
    {


        private TestContext testContextInstance;

        /// <summary>
        ///Gets or sets the test context which provides
        ///information about and functionality for the current test run.
        ///</summary>
        public TestContext TestContext
        {
            get
            {
                return testContextInstance;
            }
            set
            {
                testContextInstance = value;
            }
        }

        #region Additional test attributes
        // 
        //You can use the following additional attributes as you write your tests:
        //
        //Use ClassInitialize to run code before running the first test in the class
        //[ClassInitialize()]
        //public static void MyClassInitialize(TestContext testContext)
        //{
        //}
        //
        //Use ClassCleanup to run code after all tests in a class have run
        //[ClassCleanup()]
        //public static void MyClassCleanup()
        //{
        //}
        //
        //Use TestInitialize to run code before running each test
        //[TestInitialize()]
        //public void MyTestInitialize()
        //{
        //}
        //
        //Use TestCleanup to run code after each test has run
        //[TestCleanup()]
        //public void MyTestCleanup()
        //{
        //}
        //
        #endregion

        /// <summary>
        ///A test for TableColumnCollection Constructor
        ///</summary>
        [TestMethod()]
        [ExpectedException(typeof(ArgumentNullException))]
        public void The_Constructor_Does_Not_Accept_Null()
        {
            TableColumnCollection target = new TableColumnCollection(null);
        }

        [TestMethod()]
        [ExpectedException(typeof(ArgumentOutOfRangeException))]
        public void Should_Be_Able_To_Search_Not_Existing_Columns_Columns()
        {
            DataTable dt = new DataTable("Table 1");
            dt.Columns.Add("col1", typeof (string));

            TableColumnCollection target = new TableColumnCollection(dt.Columns);
            
            Assert.AreEqual(null, target["col2"]);
            Assert.AreEqual(null, target[1]);
        }


        /// <summary>
        ///A test for Item
        ///</summary>
        [TestMethod()]
        public void String_Indexer_Should_Return_TableColumn_Added_For_ColumnName()
        {
            const string COLUMN_NAME = "Col1";
            Type TYPE = typeof(int);

            DataTable table = new DataTable();

            table.Columns.Add(COLUMN_NAME, TYPE);

            TableDefinition target = new TableDefinition(table);

            TableColumn actual = target.Columns[COLUMN_NAME];

            Assert.AreEqual(COLUMN_NAME, actual.ColumnName);
            Assert.AreEqual(TYPE, actual.DataType);
        }

        /// <summary>
        ///A test for Item
        ///</summary>
        [TestMethod()]
        public void Numeric_Indexer_Should_Return_TableColumn_Added_For_Index()
        {
            const string COLUMN_NAME = "Col1";
            Type TYPE = typeof(int);

            DataTable table = new DataTable();

            table.Columns.Add(COLUMN_NAME, TYPE);

            TableDefinition target = new TableDefinition(table);

            TableColumn actual = target.Columns[0];

            Assert.AreEqual(COLUMN_NAME, actual.ColumnName);
            Assert.AreEqual(TYPE, actual.DataType);
        }

        /// <summary>
        ///A test for Columns
        ///</summary>
        [TestMethod()]
        public void Should_Add_Column()
        {
            const string COLUMN_NAME = "Col1";
            Type TYPE = typeof(int);

            DataTable table = new DataTable();

            table.Columns.Add(COLUMN_NAME, TYPE);

            TableDefinition target = new TableDefinition(table);
            TableColumnCollection actual = target.Columns;

            Assert.AreEqual(1, actual.Count);

            Assert.AreEqual(COLUMN_NAME, actual[0].ColumnName);
            Assert.AreEqual(TYPE, actual[0].DataType);

            Assert.AreEqual(COLUMN_NAME, actual[COLUMN_NAME].ColumnName);
            Assert.AreEqual(TYPE, actual[COLUMN_NAME].DataType);
        }
    }
} 
